import java.util.Arrays;
import java.util.Comparator;

public class ArraysSort {

	public static void main(String[] args) {
		String[] days = { "Monday", "Tuesday", "Friday", "Saturday", "Sunday" };
		Arrays.sort(days);
		System.out.println(Arrays.toString(days));
		//System.out.println(days);
		
		String[] words = { "programming", "Pascal", "print", "Perl", "Joe",
				"Java", "jdk", "alpha", "Alpha", "beta", "Beta" };
		Arrays.sort(words);
		System.out.println("default: " + Arrays.toString(words));

		System.out.println("Pascal position: "
				+ Arrays.binarySearch(words, "Pascal"));
		System.out.println("Basic position: "
				+ Arrays.binarySearch(words, "Basic"));

		Comparator<String> ignoreCaseComparator = new Comparator<String>() {
			public int compare(String a, String b) {
				return a.toLowerCase().compareTo(b.toLowerCase());
			}
		};

		Arrays.sort(words, ignoreCaseComparator);

		System.out.println("case insensitive: " + Arrays.toString(words));

		System.out.println("Pascal position: "
				+ Arrays.binarySearch(words, "Pascal", ignoreCaseComparator));
		System.out.println("Basic position: "
				+ Arrays.binarySearch(words, "Basic", ignoreCaseComparator));

		// bad usage example:
		System.out.println("Bad Pascal position: "
				+ Arrays.binarySearch(words, "Pascal"));

		// clean everything before java:
		Arrays.fill(words, 0, Arrays.binarySearch(words, "Java",
				ignoreCaseComparator), "-");
		System.out.println("After cleaning: " + Arrays.toString(words));

	}



}
